package com.team7.happycommunity.propertymanagement.controller;

import com.team7.happycommunity.propertymanagement.common.CommonResult;
import com.team7.happycommunity.propertymanagement.pojo.AreaInfo;
import com.team7.happycommunity.propertymanagement.pojo.PropertyManage;
import com.team7.happycommunity.propertymanagement.service.AreaInfoService;
import com.team7.happycommunity.propertymanagement.service.PropertyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/area")
public class AreaController {

    @Autowired
    AreaInfoService areaInfoService;

    @Autowired
    PropertyService propertyService;

    @GetMapping("/getone")
    @ResponseBody
    public CommonResult getOne(String username){
        PropertyManage propertyManage = propertyService.selectOneByUsername(username);
        AreaInfo areaInfo = areaInfoService.selectByPrimaryKey(propertyManage.getVillageId());
        List<AreaInfo> list_areainfo = new ArrayList<>();
        list_areainfo.add(areaInfo);
        return CommonResult.success(list_areainfo);
    }

    @GetMapping("/getall")
    @ResponseBody
    public  CommonResult getAll(){
        List<AreaInfo> list_areainfo = areaInfoService.selectAll();
        return CommonResult.success(list_areainfo);
    }
}
